#ifndef _CLIENT_SOCKET_H_
#define _CLIENT_SOCKET_H_

#include <stdio.h>
#include <iostream>
#include <thread>
#include <functional>

#include "pkg_define.h"
#include "ring_mem.h"

#define BLOCK_SIZE 1024 * 40  //40K

class IpcClientBase {
public:
  using RecvCB = std::function<int(char *data, int len)>;

  IpcClientBase();
  virtual ~IpcClientBase();

  int ConnectServer(std::string ip = "127.0.0.1", int port = 10500);
  int Disconnect();

  int Send(PkgHeader *header, const char *data, int len);
  void SetCb(RecvCB cb);

private:
  static int RecvLoop(IpcClientBase *pthis);

  std::string m_ip;
  int m_port;
  int m_sockfd;
  int m_efd_thread;
  bool is_running_thread;

  std::thread thread_recv;
  RingMem m_ring_mem{BLOCK_SIZE};

  RecvCB m_recv_cb;
};

#endif  // endif _CLIENT_SOCKET_H_
